package com.bq.gametrade.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.ViewGroup;

import com.bq.gametrade.ui.fragment.FriendFragment;
import com.bq.gametrade.ui.fragment.MyAccountFragment;
import com.bq.gametrade.ui.fragment.TradingFragment;
import com.bq.gametrade.ui.fragment.HomeFragment;

/**
 * Created by sony-song on 2015/3/18.
 */
public class FragmentAdapter extends FragmentPagerAdapter {

    public final static int TAB_HOME = 0;
    public final static int TAB_TRADING = 1;
    public final static int TAB_ACCOUNT = 3;
    public final static int TAB_FRIEND = 2;
    public final static int TAB_SUM = 4;

    public Fragment fragment_home, fragment_trading, fragment_account,fragment_friend;
    private FragmentTransaction fragmentTransaction;

    public FragmentAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int i) {
        Fragment fragment;
        switch (i) {
            default:
            case TAB_HOME:
                if (fragment_home == null) {
                    fragment_home = new HomeFragment();
                }
                fragment = fragment_home;
                break;
            case TAB_TRADING:
                if (fragment_trading == null) {
                    fragment_trading = new TradingFragment();
                }
                fragment = fragment_trading;
                break;
            case TAB_FRIEND:
                if (fragment_friend == null) {
                    fragment_friend = new FriendFragment();
                }
                fragment = fragment_friend;
                break;
            case TAB_ACCOUNT:
                if (fragment_account == null) {
                    fragment_account = new MyAccountFragment();
                }
                fragment = fragment_account;
                break;


        }
        return fragment;
    }

    @Override
    public int getCount() {
        return TAB_SUM;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        super.destroyItem(container, position, object);
    }

    @Override
    public void destroyItem(View container, int position, Object object) {
        super.destroyItem(container, position, object);
    }
}
